package com.lagou.controller;

import com.lagou.domain.Employee;
import com.lagou.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import java.text.SimpleDateFormat;
import java.util.List;

@Controller
@RequestMapping("/employee")
public class EmployeeController {


    @Autowired
    EmployeeService employeeService;


    @RequestMapping("/findAll")
    public ModelAndView findAll(){
        List<Employee> employeeList = employeeService.findAll();
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("employeeList",employeeList);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        modelAndView.addObject("simpleDateFormat",simpleDateFormat);
        modelAndView.setViewName("list");
        return modelAndView;
    }


    @RequestMapping("/save")
    public String save(Employee employee){
        System.out.println(employee);
        employeeService.save(employee);
        return "redirect:/employee/findAll";
    }

}
